func reverseWords(s string) string {
    lenS := len(s)
    byteS := []byte(s)
    slowIndex, fastIndex := 0, 0

    // 出去前面的空格
    for lenS > 0 && fastIndex < lenS && byteS[fastIndex] == ' ' {
        fastIndex++
    }

    // 去除中间的空格
    for ; fastIndex < lenS ; fastIndex++ {
        if fastIndex - 1 > 0 && byteS[fastIndex] == byteS[fastIndex - 1] && byteS[fastIndex] == ' ' {
            continue
        }
        byteS[slowIndex] = byteS[fastIndex]
        slowIndex++
    }

    // 去除末尾的空格
    if slowIndex-1 > 0  && byteS[slowIndex-1] == ' ' {
        byteS = byteS[:slowIndex-1]
    } else {
        byteS = byteS[:slowIndex]
    }

    // 反转整个字符串
    reverse(&byteS, 0, len(byteS)-1)

    // // 反转单词
    i := 0
    for i < lenS {
        j := i
        for ; j < len(byteS) && byteS[j] != ' '; j++{
        }
        reverse(&byteS, i, j-1)
        i = j + 1
    }

    return string(byteS)

}

func reverse(s *[]byte, start int, end int) {
    for start < end {
        (*s)[start], (*s)[end] = (*s)[end], (*s)[start]
        start++
        end--
    }
}